<template>
	<view>
		<chose-city @selectCity="selectCity" v-if="showCity" @closeModal="closeModal"></chose-city>
	</view>
</template>

<script>
	import choseCity from "@/components/chose-city/chose-city"
	export default {
		components: {
			choseCity
		},
		data() {
			return {
				showCity: true // 默弹窗显示
			}
		},
		methods: {
			selectCity(item) {
				let _this = this

				uni.request({
					url: "https://restapi.amap.com/v3/geocode/geo",
					method: 'GET',
					data: {
						key: '6d77b7119a4fb52745394ea5590ccf52',
						address: item.name
					},
					success: (res) => {
						var arr = res.data.geocodes[0].location.split(',')
						// uni.reLaunch({
						// 	url:'./shopList?longitude='+arr[0]+'&latitude='+arr[1]+'&name='+item.name
						// })

						var parameter = {
							longitude: arr[0],
							latitude: arr[1],
							name: item.name,
							type:1
						}
						uni.$emit("handleAddress", {
							parameter: parameter
						});
						uni.navigateBack(1)
						this.showCity = false
					},
					fail(err) {
						console.log(err)
						_this.addressName = '定位失败'
					}
				})
				console.log('-您选择的城市-', item)

			},
			closeModal() {
				this.showCity = false
			},
		}
	}
</script>

<style>

</style>
